import { _decorator, Collider2D, Component, Contact2DType, instantiate, IPhysics2DContact, math, Node, Prefab } from 'cc';
const { ccclass, property } = _decorator;

export enum prwardType {
    prward1 = 1, // 奖励类型1
    prward2 = 2, // 奖励类型2
}
@ccclass('prward1')
export class prward1 extends Component {

    @property
    prwardType: prwardType = prwardType.prward1; // 奖励类型

    @property
    speed: number = 3; // 奖励下降速度


    collider: Collider2D = null;   // 碰撞组件

    start() {
        this.collider = this.getComponent(Collider2D);
        if (this.collider) {
            this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
        } else {
            console.log('组件未找到')
        }



    }

    update(deltaTime: number) {

        let position = this.node.position;
        // 每帧向下移动
        this.node.setPosition(position.x, position.y - this.speed * deltaTime, position.z);

        if (position.y < -700) {
            // 如果超出边界，销毁节点
            this.node.destroy();
        }
    }

    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        this.scheduleOnce(() => {
            this.node.destroy();
        });
    }
}
